﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using XProject.DataVisit.Factory;
using XProject.DataVisit.Model.Role;

namespace XProject.DataVisit.Model
{
    public class UserInfo:IProjectModel
    {
        public virtual Guid PID { get; set; }

        /// <summary>
        /// 用户登录名
        /// </summary>
        public virtual string UserAccount { get; set; }
        /// <summary>
        /// 用户密码
        /// </summary>
        public virtual string UserPass { get; set; }
        /// <summary>
        /// 用户姓名
        /// </summary>
        public virtual string UserName { get; set; }
        /// <summary>
        /// 所在地址
        /// </summary>
        public virtual Guid Address { get; set; }

        /// <summary>
        /// 公司名称
        /// </summary>
        public virtual string Company { get; set; }
        /// <summary>
        /// 联系电话
        /// </summary>
        public virtual string Tel { get; set; }

        /// <summary>
        /// 邮件
        /// </summary>
        public virtual string Email { get; set; }

        /// <summary>
        /// 年龄
        /// </summary>
        public virtual string Age { get; set; }
        /// <summary>
        /// 用户分成比例
        /// </summary>
        public virtual double UserInto { get; set; }
        /// <summary>
        /// 职称
        /// </summary>
        public virtual string Job { get; set; }
        /// <summary>
        /// 所属角色
        /// </summary>
        public virtual Guid RoleID { get; set; }

        /// <summary>
        /// 所属角色名称
        /// </summary>
        public virtual string RoleName { get; set; }

        /// <summary>
        /// 更新日期
        /// </summary>
        public virtual DateTime LastUpdate { get; set; }

        public virtual string NTime {
            get { return LastUpdate.ToString("yyyy-MM-dd"); }
        }

        /// <summary>
        /// 所在地区
        /// </summary>
        public virtual Area ChargeArea {
            get {
                if (Address != Guid.Empty)
                    return DaoFactory.AreaDao.GetById(Address);
                return null;
            }
        }

        /// <summary>
        /// 用户所属权限
        /// </summary>
        public virtual IList<GYAccess> UserRight
        {
            get
            {
                if (RoleID != Guid.Empty)
                    return DaoFactory.RoleDao.GetById(RoleID).RoleRight;
                return null;
            }
        }

        #region 重写Hash和Equals
        public override int GetHashCode()
        {
            return PID.GetHashCode();
        }
        
        public override bool Equals(object obj)
        {
            var temp = obj as UserInfo;
            if (temp == null) return false;
            return temp.PID == this.PID;
        }
        #endregion
    }
}
